//! \file config.cpp Defines somes log path based methods e.g. get the path to the log file

#include "StdAfx.h"
#include "config.h"
#include "resource.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

using namespace std;


string CConfig::getossandcadTempPath()
{
	char cPath[MAX_PATH];
	string path = "";

	// get the user specific temp path
	if( GetTempPathA(MAX_PATH, cPath) ) 
	{
		// add \ossandcad\ to %TEMP%
		path = string(cPath) + GetString(IFC_ossandcad_TEMP_PATH);
	}
	return path;
}

string CConfig::getLogPath()
{
	string path;
	createossandcadTempPath(path);
	path += GetString(LOG_PATH_TO_LOG);
	return path;
}

unsigned int CConfig::createossandcadTempPath(string & path)
{
	path = getossandcadTempPath();
	// if it does not exists create it
	if( !PathFileExistsA(path.c_str()) ) {
		return CreateDirectoryA(path.c_str(), NULL) ? 0 : LOG_FAILED_CREATE_DIR;
	}
	return 0;
}

std::string CConfig::GetString(unsigned int ID) {
	char cError[MAX_PATH];
	if( LoadStringA(GetModuleHandle(_T("Log")), ID, cError, sizeof(cError)/sizeof(cError[0])) )
		return string(cError);
	else return string("");
}